package timer

import (
	"errors"
)

var cli ClientImpl

var ErrNoClient = errors.New("no client was set")

type ClientImpl interface {
	Get(int64) (*Data, error)
	GetAll() ([]*Data, error)
	Add(int64, string, *Repeat) (int64, error)
	Remove(int64) error
}

func SetClient(c ClientImpl) {
	if cli == nil {
		cli = c
	}
}

func Get(id int64) (*Data, error) {
	if cli == nil {
		return nil, ErrNoClient
	}
	return cli.Get(id)
}

func GetAll() ([]*Data, error) {
	if cli == nil {
		return nil, ErrNoClient
	}
	return cli.GetAll()
}

func Add(ts int64, url string, repeat *Repeat) (id int64, err error) {
	if cli == nil {
		return 0, ErrNoClient
	}
	return cli.Add(ts, url, repeat)
}

func Remove(id int64) error {
	if cli == nil {
		return ErrNoClient
	}
	return cli.Remove(id)
}
